package com.example.consumer_ribbon.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/order/user/getById")
    @ResponseBody
    public Object getUserById(String id){
        System.out.println("--------------------"+id+"--------------");
        String url = "http://eureka-user/user/getById?id=" + id;
//        String url = "http://EUREKA_USER/user/getById?id=" + id;
//        String url = "http://localhost:8081/user/getById?id=" + id;
        return restTemplate.getForObject(url, Object.class);
    }

    @RequestMapping("/order/getIpAndPort")
    @ResponseBody
    public String getIpAndPort(){
        String url = "http://provider-user/getIpAndPort";
        return restTemplate.getForObject(url, String.class);
    }

}
